<template>
  <div class="GCooperativeSiteReportList">
    <filterPanel filterName="GCooperativeSiteReportListFilter" filterTitle="合作站点收寄件列表查询" :filterList="filterData"
                 @filterChange="filterChange"></filterPanel>
    <tablePanel tableName="GCooperativeSiteReportListTable" :tableLoading="loading" tableTitle="合作站点收寄件列表"
                :tableList="tableList" :tableData="tableData" :total="total" :currentPage="form.page_start"
                :pageSize="form.page_size" @sizeChange="sizeChange" @pageChange="pageChange" @tableClick="tableClick">
      <div class="total-box">
        <div class="total-info">寄件合计<span>（{{send_count}}）</span>件</div>
        <div class="total-info">收件合计<span>（{{rec_count}}）</span>件</div>
        <div class="total-info">总计<span>（{{ttnum}}）</span>件</div>
      </div>
      <zy-button type="primary" @click="exportExcel">导出列表</zy-button>
    </tablePanel>
  </div>
</template>

<script>
	import {mapGetters} from "vuex";

	export default {
		name: "GCooperativeSiteReportList",
		props: {},
		data() {
			return {
				currentPath: '/cooperative_site_report_list',
				filterData: [
					{
						title: '合作站点名称',
						name: 'company_name',
						type: 'input',
						value: '',
						isShow: true,
						isSelected: true
					},
					{
						title: '统一社会信用代码',
						name: 'organization_code',
						type: 'input',
						value: '',
						isShow: true,
						isSelected: true
					},
					{
						title: '法人姓名',
						name: 'legal_person',
						type: 'input',
						value: '',
						isShow: true,
						isSelected: true
					},
					{
						title: '法人联系方式',
						name: 'legal_phone',
						type: 'input',
						value: '',
						isShow: true,
						isSelected: true
					},
					{
						title: '收寄件时间',
						name: 'registration_date',
						type: 'date',
						value: [],
						isShow: true,
						isSelected: true
					},
				],
				form: {
					company_name: '',
					organization_code: '',
					legal_person: '',
					legal_phone: '',
					registration_date: [],
					page_start: 1,
					page_size: 10
				},
				loading: false,
				tableList: [
					{
						title: '合作站点名称',
						width: 200,
						name: 'company_name',
						isShow: true,
						isSelected: true
					},
					{
						title: '统一社会信用代码',
						width: 200,
						name: 'organization_code',
						isShow: true,
						isSelected: true
					},
					{
						title: '法人姓名',
						width: 120,
						name: 'legal_person',
						isShow: true,
						isSelected: true
					},
					{
						title: '法人联系方式',
						width: 160,
						name: 'legal_phone',
						isShow: true,
						isSelected: true
					},
					{
						title: '从业人数',
						width: 160,
						name: 'company_count',
						isShow: true,
						isSelected: true
					},
					{
						title: '寄件数量',
						width: 160,
						name: 'send_count',
						isShow: true,
						isSelected: true
					},
					{
						title: '收件数量',
						width: 160,
						name: 'rec_count',
						isShow: true,
						isSelected: true
					},
					{
						title: '共计',
						width: 160,
						name: 'logist_num',
						isShow: true,
						isSelected: true
					},
					{
						title: '操作',
						width: 150,
						name: 'handler',
						fixed: 'right',
						btns: [
							{
								type: 'detail',
								name: '详情'
							},
						],
						isSelected: true
					}
				],
				tableData: [],
				total: 0,
				download_url: '',
				rec_count: 0,
				send_count: 0,
				ttnum: 0
			};
		},
		computed: {
			postData() {
				let data = {
					company_name: this.form.company_name,
					organization_code: this.form.organization_code,
					legal_person: this.form.legal_person,
					legal_phone: this.form.legal_phone,
					empnum: this.form.empnum,
					pagination: {
						page_start: this.form.page_start,
						page_size: this.form.page_size
					}
				};
				if (this.form.time && this.form.time.length > 0) {
					data.start_time = this.form.time[0] / 1000;
					data.end_time = this.form.time[1] / 1000;
				}
				return data;
			},
			...mapGetters(['authority']),
			isLook() {
				return this.authority[this.currentPath] && this.authority[this.currentPath].l;
			},
		},
		watch: {},
		components: {},
		methods: {
			//导出
			exportExcel() {
				this.$import_excal(this.download_url || "");
			},
			sizeChange(val) {
				this.form.page_size = val;
				this.getData()
			},
			pageChange(val) {
				this.form.page_start = val;
				this.getData()
			},
			filterChange(data) {
				this.form = {...this.form, ...data};
				this.getData();
			},
			getData() {
				this.loading = true;
				this.tableData = [];
				this.$axios.post(this.$api.g_cooperLogisticsReport, {...this.postData}).then(res => {
					let {code, msg, data} = res;
					this.loading = false;
					if (code == 200) {
						this.tableData = data.list.filter(item => {
							item.num = item.rec_count + item.send_count + item.logist_num
							item.detail = this.isLook || true
							return item;
						});
						this.download_url = data.download_url || ''
						this.total = data.pagination.total_count || 0;
						this.rec_count = data.rec_count || 0;
						this.send_count = data.send_count || 0;
						this.ttnum = data.ttnum || 0;
					} else {
						this.total = 0
						this.tableData = [];
						this.rec_count =  0;
						this.send_count = 0;
						this.ttnum =  0;
					}
				}).catch(ret => {
					this.loading = false;
					this.$message.error(ret.msg || '服务繁忙，请稍后再试');
				});
			},
			tableClick(data, type) {
				this.$toRoutePath({
					path: "/cooperative_site_report_list/cooperative_site_report_detail",
					edit: true,
					query: {cooper_id:data.company_id}
				});
			},
		},
		mounted() {
			this.getData()
		},
		created() {
		}
	}
</script>

<style scoped lang="less" src="@/style/government/reportManage/cooperativeSiteList/index.less">

</style>
